'''
    该案例演示比较,逻辑运算符
'''
# -----------比较运算符--------------------------
# num1 = 10
# num2 = 20
# # ==  相等,比较运算符
# print(num1 == num2)
# # != 不相等
# print(num1 != num2)
# # > 大于
# print(num1 > num2)
# # < 于
# print(num1 < num2)
# # >= 大于
# print(num1 >= num2)
# # <= 于
# print(num1 <= num2)

# ------------逻辑运算符--------------------------
# and 与，描述的并且的关系,参与的比较两个数同时为true,表达式则为true,    x and y ，若x为false返回x的值，则返回y
# or 或 ，描述的或者的关系,参与运算两个数只要有一个为true,表达式则为true, x or y ，若x为true返回x的值,则返回y
# not 非, not x 若x为true返回false,若x为false则返回true
b1= False
b2= True

# print(b1 and b2)  # False
# print(b1 or b2)    #True
# print(not b1)     # True
# print(not b2)   # False

# print(5 and 8)   #8
# print(5 or 8)    #5
# print(not  5)    # false


# ~~~~~~~~~~~位运算符~~~~~~~~~~~~~~~~
# num1 = 17
# num2 = 13
#
# print(f"正数与运算: {num1} & {num2}")
# print(f"{num1:3} : {num1:08b}")
# print(f"{num2:3} : {num2:08b}")
# print(f"{num1 & num2:3} : {num1 & num2:08b}")
# print()
#
# print(f"正数或运算: {num1} | {num2}")
# print(f"{num1:3} : {num1:08b}")
# print(f"{num2:3} : {num2:08b}")
# print(f"{num1 | num2:3} : {num1 | num2:08b}")
# print()
#
# print(f"正数异或运算: {num1} ^ {num2}")
# print(f"{num1:3} : {num1:08b}")
# print(f"{num2:3} : {num2:08b}")
# print(f"{num1 ^ num2:3} : {num1 ^ num2:08b}")
# print()
#
# print(f"非运算: ~{num1}")
# print(f"{num1:3}原码 : {num1:08b}")
# print(f"{num1:3}取反 : {(1 << 8) - 1 ^ num1:08b}，得到结果的补码")
# print(f"{~num1:3}原码 : {~num1:08b}，计算出结果的原码")


# ----------------成员运算符-------------------------
# num1 = 10
# num2 = 60
# numbers  = [10,20,30,40,50]
# print(num1 in numbers)   # true
# print(num2 in numbers)    # false

# ---------------身份运算符--------------
m = 20
n = 20
q = 30
print(m is n)  #true 判断m和m在内存中是否指向同一个地址
print(n is q)  # false
print(n  is not q)  # true
# id() 用于获取对象在内存中的地址
print(id(n) == id(m))

#-------------------is 和 == 的区别---------------------------------------
a = [1,2,3]
c = a
print(a == c)  #true
print(a is c)  #true

c = a [:]   # 相当于浅拷贝
print(c)
print(id(c) == id(a),"111") # false
print(a is c)   # false
print(a == c)   # true


